Lab 2: Scheduling Simulation
In this lab, you will write a program to simulate a first come first serve and a shortest job first scheduler.  This scheduler will take a file as input, and run the appropriate scheduling algortithm over the input file.
Getting Started:
Download the files:
schedulingShort.txt  Download schedulingShort.txt:  a file containing the input for a 10 job run of the simulation
queue.h  Download queue.h: the include file for a queue to hold Job records
queue.c  Download queue.c: the implementation of the job queue
schedulingSim.c  Download schedulingSim.c: the main simulation file that you will need to complete
schedulingLong.txt  Download schedulingLong.txt:  a file containing the input for a large run of the simulation.
Create a working area for your simulation.  You can do this on any machine with a working C compiler -- you do not need to do this on your devbox machine.  

Examine the files you downloaded:

In schedulingShort.txt, each line represents one job in the form of <arrival Time> <length of job>.  So, a line like:
20 14
would indicate a job arriving at time 20, that needs to run for 14 time steps.  This file will control the simulation.

You should go through this file and determine what the correct results should be for your simulation -- with only 10 jobs, you should be able to manually determine the correct times that each job will start and end.

Look at queue.h to see what functions and data structures are available for you.  You have:

queueAdd -- add a Job to the queue
queueRemoveFirst -- remove the Job from the head of the queue
queueRemoveShortest -- find and remove the shortest Job on the queue
queueIncrementWaitTimes -- increment the wait time by one for each job currently on the queue

I have supplied a Job data structure for you use -- it consists of two fields.  The duration is the length of time this job needs to run, and a waitTime field for collecting waitTimes.  NOTE: you *must* set the waitTime to 0 when you create your Job to add to the queue.

Look at schedulingSim.c.  It contains several functions:

main: reads the command line arguments and opens the input file
jobArrives: a helper function that reads the file line by line, and returns the next job to arrive.
doSimulation: an empty function that you will fill in.
What you need to do:
Complete the doSimulation function and simulate the behavior of a first come first serve scheduler and a shortest job next scheduler.  It should collect the following information:
•	the number of jobs contained in the input file
•	the total time it takes for the entire simulation
•	the total amount of time the jobs ran for -- note that this is not the same as the time for the simulation, since the processor might have to wait for work at times
•	the total amount of time that jobs spent waiting -- note that this does not have to be saved on a job by job basis -- you just need to sum up the wait time for all the jobs combined
•	the maximum length of the job queue during the simulation
•	the average wait time for each job

Here is an example of what your program might look like (this is not with the file you will be using):

# OS_schedulingSimulator FCFS ../schedulingExample.txt
Running simulation for first come first serve
Started job 1 at timestep 2 for duration 1
Started job 2 at timestep 3 for duration 4
Started job 3 at timestep 21 for duration 1
Started job 4 at timestep 45 for duration 3
Started job 5 at timestep 80 for duration 10
Started job 6 at timestep 90 for duration 4
Started job 7 at timestep 94 for duration 7
Started job 8 at timestep 130 for duration 47
Started job 9 at timestep 177 for duration 10
Started job 10 at timestep 187 for duration 12
Ran for 198 time steps.  Total jobs run: 10  Max queue length: 2
Total job runtime: 99, total wait time: 100
Average wait time: 10.000000

Note that the lines like:

        Started job 1 at timestep 16 for duration 8

are only for debugging purposes.   However, this form of debugging can be helpful until you are sure that your program is running correctly. The only required output is the information at the beginning and the end:

Running simulation for first come first serve

Ran for 198 time steps.  Total jobs run: 10  Max queue length: 2
Total job runtime: 99, total wait time: 100
Average wait time: 10.000000
Completion
Once you have your simulation fully debugged, run your program against the schedulingLong.txt  Download schedulingLong.txtfile.  Please be sure you are only reporting your final numbers-- not any per job information.  As an example, the program output shown above would be incorrect -- it should not include the lines "Starting job1 at ....".  Once you have removed any extra debugging like that, you should run the following commands:

# OS_schedulingSimulator FCFS schedulingLong.txt >> longFCFSoutput.txt

# OS_schedulingSimulator SJF schedulingLong.txt >> longSJFoutput.txt

and save the output of both commands to a pair of text files.

An Extra Challenge, for fun
If you wish, you may *add* a third scheduling option to your program.  This would simulate a shortest job first scheduler with preemption.  You'll need to make changes both to main() and doSimulation to make this work.  For this task, please submit output showing your scheduling result, perhaps like this:
# OS_schedulingSimulator SJFP ../schedulingLong.txt
Submit:
Once you are comfortable that all is working, submit the following files:
1.	your simulation .c file
2.	one or more text files showing the results of the commands described above.
3.	you may also submit a third form of scheduling, the pre-emptive SJF results. 
If you do extra work, such as this, it can help restore points lost on other labs.